/*
 * @Author: Shiire
 * @Date: 2022-02-16 15:30:00
 * @LastEditors: Shiire
 * @LastEditTime: 2022-08-20 20:37:04
 * @Description: 
 * @FilePath: \grapro\src\main.js
 */
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'video.js/dist/video-js.css'; //videojs样式
import Vue from 'vue';
import VueAxios from 'vue-axios';
import VueSocketIO from 'vue-socket.io';
import App from './App.vue';
import router from './router';
import axios from './utils/instance';

Vue.config.productionTip = false


Vue.use(VueAxios, axios)

// 获取自己的信息
Vue.prototype.$getuserinfo = (callback) => {
  axios
    .get(`getuserinfo`)
    .then((response) => {
      if (response.data.status == 200) {
        // console.log(response);
        callback(response.data.data)
      } else {
        console.log(response);
      }
    })
    .catch((err) => {
      console.log(err);
    });
}


// 获取自己的收藏
Vue.prototype.$getcollection = (id, callback) => {
  // console.log(id)
  axios
    .get(`getcollection/${id}`)
    .then((response) => {
      if (response.data.status == 200) {
        // console.log(response);
        callback(response.data.data)
      } else {
        console.log(response);
      }
    })
    .catch((err) => {
      console.log(err);
    });
}


Vue.use(ElementUI);

let socketUrl = process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:3000' : 'http://42.192.69.157:3000'

Vue.use(new VueSocketIO({
  debug: true,
  connection: socketUrl,
  // connection: 'http://42.192.69.157:3000',

  options: {     //Optional options, 
    autoConnect: false, //关闭自动连接，在用户登录后在连接。
  }
}))

new Vue({
  sockets: {
    connecting() {
      console.log('正在连接')
    },
    disconnect() {
      console.log("Socket 断开");
    },
    connect_failed() {
      cosnole.log('连接失败')
    },
    connect() {
      console.log('socket connected')
    },
  },
  router,
  render: h => h(App)
}).$mount('#app')
